
import  File  from './basics/File.js'
import  Square from './basics/Square.js'
import Row from './basics/Row.js'

export default class TemplateFile extends File{
    constructor(){
        super()
       let _this=this;
        _this.paras=new Square();
        _this.comms=new Square();
        _this.paras.addRow(new Row(44444,null,null,5))
        _this.comms.addRow(new Row(1,1,1,5))
    }

    saveData(FileId,SquareId,RowId,dataThis){
        debugger
        dataThis.list[this.ln-1]=this.para;
        debugger
    }

    /**
     * 运行
     */
    compile(){
        let _this=this;
        debugger
        for (let i=0;i<_this.comms.list.length;i++){
            let comm=_this.comms.list[i];
           let para=  _this.findPara(comm.find(4))
            if(para!==null){
                _this.para=para;
                _this.ln=comm.find(3)
               _this.findData(0,comm.find(1),comm.find(2) ,_this.saveData.bind(_this))
            }
        }

        return this.outData();
    }

    /**
     *
     * @param name
     * @returns {null}
     */
    findPara(name){

        for (let i=0;i<this.paras.list.length;i++){

           if(this.paras.list[i].isValue(4,name)) {
               return this.paras.list[i].find(1)
           }

        }

        return null;
    }

    /*添加模板
     */
    addTem(data){
        this.loadData(data);
    }

    /**
     * 添加命令
     */
    addComm(comms){
        this.comms=comms;
    }

}